//
//  DetailNewCell.m
//  FruitsWholesaler
//
//  Created by sgone-2 on 16/4/19.
//  Copyright © 2016年 sgone. All rights reserved.
//

#import "DetailNewCell.h"
#import "Common.h"
@implementation DetailNewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.backgroundColor = [UIColor whiteColor];
    
    
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(8, 8/FDLaOt, ViewWidth - 8* 2 , 30/FDLaOt *5 + 40/FDLaOt)];
    view1.backgroundColor = [UIColor whiteColor];
    [self addSubview:view1];
    view1.layer.masksToBounds = YES;
    view1.layer.cornerRadius = 8.0;
    view1.layer.borderColor = FDBCellColor.CGColor;
    view1.layer.borderWidth = 1.0f;
    
    
    
    for (int i = 0; i < 4; i++)
    {
        UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(8, 30/FDLaOt *i+ 30/FDLaOt, ViewWidth - 8*2, 30/FDLaOt)];
        lbl.font = [UIFont systemFontOfSize:13/FDLaOt];
        [view1 addSubview:lbl];
        lbl.textColor = [UIColor grayColor];
        
        
        switch (i) {
            case 0:
               lbl.text = @"送货地址 :";
                break;
            case 1:
                lbl.text = @"送货距离 :";
                break;
            case 2:
                lbl.text = @"下单时间 :";
                break;
             case 3:
                lbl.text = @"送货时间 :";
                break;
            default:
                break;
        }

    }
    
    
    
    self.lbl11 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ViewWidth - 8*2, 30/FDLaOt)];
    self.lbl11.backgroundColor = FDBCellColor;
    self.lbl11.textAlignment = NSTextAlignmentCenter;
    self.lbl11.font = [UIFont systemFontOfSize:15/FDLaOt];
    [view1 addSubview:self.lbl11];
    self.lbl11.textColor = [UIColor whiteColor];
    
    
    
    self.lbl = [[UILabel alloc]initWithFrame:CGRectMake(8, 4/FDLaOt, 22/FDLaOt, 22/FDLaOt)];
    self.lbl.textColor = BenSe_COLOR;
    self.lbl.backgroundColor = [UIColor whiteColor];
    [view1 addSubview:self.lbl];

    self.lbl.textAlignment = NSTextAlignmentCenter;
    self.lbl.layer.masksToBounds = YES;
    self.lbl.layer.cornerRadius = 11/FDLaOt;


    
    
    
    self.lbl1 = [[UILabel alloc]initWithFrame:CGRectMake(70, 30/FDLaOt, ViewWidth - 120, 30/FDLaOt)];
    [view1 addSubview:self.lbl1];
    self.lbl1.font = [UIFont systemFontOfSize:11/FDLaOt];
    self.lbl1.textColor = [UIColor grayColor];
    
    self.lbl1.backgroundColor = [UIColor whiteColor];
    
    self.lbl2 = [[UILabel alloc]initWithFrame:CGRectMake(70, 30/FDLaOt*2, ViewWidth - 120, 30/FDLaOt)];
    [view1 addSubview:self.lbl2];
    self.lbl2.font = [UIFont systemFontOfSize:13/FDLaOt];
    self.lbl2.textColor = [UIColor grayColor];
    
    
    
    self.lbl3 = [[UILabel alloc]initWithFrame:CGRectMake(70, 30/FDLaOt*3, ViewWidth - 120, 30/FDLaOt)];
    [view1 addSubview:self.lbl3];
    self.lbl3.font = [UIFont systemFontOfSize:13/FDLaOt];
    self.lbl3.textColor = [UIColor grayColor];
    
    
    
    
    self.lbl4 = [[UILabel alloc]initWithFrame:CGRectMake(70, 30/FDLaOt*4, ViewWidth - 120, 30/FDLaOt)];
    [view1 addSubview:self.lbl4];
    self.lbl4.font = [UIFont systemFontOfSize:13/FDLaOt];
    self.lbl4.textColor = [UIColor grayColor];
    
    
    
    UILabel *lbl5 = [[UILabel alloc]initWithFrame:CGRectMake(14, 30/FDLaOt*5, view1.frame.size.width - 14*2, 0.3)];
    lbl5.backgroundColor = FDBCellColor;
    [view1 addSubview:lbl5];
    
    
    
    UILabel *lbl6 = [[UILabel alloc]initWithFrame:CGRectMake((ViewWidth -16)/2, 30/FDLaOt*5 + 10/FDLaOt, 0.4, 18/FDLaOt)];

    lbl6.backgroundColor = FDBCellColor;
    [view1 addSubview:lbl6];
    
    
    
    
    
    
    self.btn1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 30/FDLaOt*5, (ViewWidth -16)/2, 30/FDLaOt + 8/FDLaOt)];
    [self.btn1 setTitle:@"确认发货" forState:UIControlStateNormal];
    [self.btn1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.btn1 setImage:[UIImage imageNamed:@"电话"] forState:UIControlStateNormal];
    self.btn1.titleLabel.font = [UIFont systemFontOfSize:14/FDLaOt];
    [view1 addSubview:self.btn1];
    [self.btn1 setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];
 
    
    
    
    self.btn2 = [[UIButton alloc]initWithFrame:CGRectMake(ViewWidth /2, 30/FDLaOt*5, (ViewWidth -16)/2, 30/FDLaOt + 8/FDLaOt)];
    [self.btn2 setTitle:@"联系客户" forState:UIControlStateNormal];
    [self.btn2 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [self.btn2 setImage:[UIImage imageNamed:@"电话2"] forState:UIControlStateNormal];
    self.btn2.titleLabel.font = [UIFont systemFontOfSize:14/FDLaOt];
    //    self.btn1.backgroundColor = [UIColor greenColor];
    [view1 addSubview:self.btn2];
    [self.btn2 setImageEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 10)];
  
    
    
  
}

+(instancetype)cellWithTableView:(UITableView *)tableView
{
    
    NSString *ID = @"DetailNewCell";
    DetailNewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        
        cell = [[NSBundle mainBundle]loadNibNamed:@"DetailNewCell" owner:nil options:nil][0];
        
    }
  
    return cell;
    
}



-(void)loadCell:(NSDictionary *)dict
{
    
    
    
    self.lbl.text =[NSString stringWithFormat:@"%d",[self.row intValue] + 1];
   
//    self.lbl11.text = [NSString stringWithFormat:@"%@",self.dealer_name];
    if (![dict objectForKey:@"shopName"]  || [[dict objectForKey:@"shopName"] isKindOfClass:[NSNull class]]) {
        
        self.lbl11.text = @"";
    }
    else
    {
        
        self.lbl11.text = [NSString stringWithFormat:@"%@",[dict objectForKey:@"shopName"]];
        
    }
    self.lbl1.numberOfLines = 0;
    
    
    self.lbl1.text = [NSString stringWithFormat:@"    %@",dict[@"address"]];
    
    CGSize priceSize = [self sizeWithString:self.lbl1.text font:self.lbl1.font];
    
    self.lbl1.frame = CGRectMake(70, 30/FDLaOt, priceSize.width, 30/FDLaOt);
    
    self.lbl1.numberOfLines = 0;
     self.lbl2.text = [NSString stringWithFormat:@"    %.3f(公里)",[dict[@"distance"] floatValue]/1000];;
    
    
    NSString *stringDate = [NSString stringWithFormat:@"%@",[dict objectForKey:@"order_time"]];
    int ordertime = [stringDate intValue];
    NSDate *orderdate = [[NSDate alloc]initWithTimeIntervalSince1970:ordertime];
    NSDateFormatter *formatter2 = [[NSDateFormatter alloc]init];
    [formatter2 setDateFormat:@"yyy-MM-dd  HH:mm"];
    self.lbl3.text = [NSString stringWithFormat:@"    %@",[formatter2 stringFromDate:orderdate]];
    
    
    
    
    NSString *stringDate2 = [NSString stringWithFormat:@"%@",[dict objectForKey:@"point_time"]];
    int ordertime2 = [stringDate2 intValue];
    NSDate *orderdate2 = [[NSDate alloc]initWithTimeIntervalSince1970:ordertime2];
    NSDateFormatter *formatter3 = [[NSDateFormatter alloc]init];
    [formatter3 setDateFormat:@"yyy-MM-dd  HH:mm"];
   self.lbl4.text = [NSString stringWithFormat:@"    %@",[formatter3 stringFromDate:orderdate2]];

}


- (CGSize)sizeWithString:(NSString *)string font:(UIFont *)font
{
    CGRect rect = [string boundingRectWithSize:CGSizeMake(ViewWidth - 120, 8000)//限制最大的宽度和高度
                                       options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading  |NSStringDrawingUsesLineFragmentOrigin//采用换行模式
                                    attributes:@{NSFontAttributeName: font}//传人的字体字典
                                       context:nil];
    
    return rect.size;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

   
}

@end
